package com.highper.rpc.socket;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * @Author ZhangGJ
 * @Date 2022/02/18 17:44
 */
public class Client {

	public static void main(String[] args) throws Exception {
		while (true) {
			Socket socket = new Socket("127.0.0.1", 9999);
			OutputStream outputStream = socket.getOutputStream();
			System.out.println("请输入: ");
			Scanner scanner = new Scanner(System.in);
			String message = scanner.nextLine();
			outputStream.write(message.getBytes(StandardCharsets.UTF_8));
			InputStream inputStream = socket.getInputStream();
			byte[] b = new byte[1024];
			int read = inputStream.read(b);
			System.out.println("客户端说: " + new String(b, 0, read).trim());
			socket.close();
		}
	}
}
